# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
import json
from itemadapter import ItemAdapter


class DemoPipeline:
    def process_item(self, item, spider):
        return item

class JsonWriterCarPipeline(object):
    def __init__(self):
        self.file = open('bilibili_rank.json', 'wt')

    def process_item(self, item, spider):
        lines = json.dumps(dict(item), ensure_ascii=False) + "\n"
        self.file.write(lines)
        return item